class Solution(object):
    def minArea(self, image, x, y):
        """
        :type image: List[List[str]]
        :type x: int
        :type y: int
        :rtype: int
        """
        m = len(image)
        n = len(image[0])

        def search_h_upper(i, j):
            if j - i == 0:
                return i
            else:
                if j - i == 1:
                    if '1' in image[j]:
                        return j
                    else:
                        return i
                else:
                    mid_index = (i + j) // 2
                    if '1' in image[mid_index]:
                        return search_h_upper(mid_index, j)
                    else:
                        return search_h_upper(i, mid_index)

        def search_h_lower(i, j):
            if j - i == 0:
                return i
            else:
                if j - i == 1:
                    if '1' in image[i]:
                        return i
                    else:
                        return j
                else:
                    mid_index = (i + j) // 2
                    if '1' in image[mid_index]:
                        return search_h_lower(i, mid_index)
                    else:
                        return search_h_lower(mid_index, j)

        def search_v_upper(i, j):
            if j - i == 0:
                return i
            else:
                if j - i == 1:
                    if '1' in [k[j] for k in image]:
                        return j
                    else:
                        return i
                else:
                    mid_index = (i + j) // 2
                    if '1' in [k[mid_index] for k in image]:
                        return search_v_upper(mid_index, j)
                    else:
                        return search_v_upper(i, mid_index)

        def search_v_lower(i, j):
            if j - i == 0:
                return i
            else:
                if j - i == 1:
                    if '1' in [k[i] for k in image]:
                        return i
                    else:
                        return j
                else:
                    mid_index = (i + j) // 2
                    if '1' in [k[mid_index] for k in image]:
                        return search_v_lower(i, mid_index)
                    else:
                        return search_v_lower(mid_index, j)

        left_index = search_v_lower(0, y)
        right_index = search_v_upper(y, n - 1)
        up_index = search_h_lower(0, x)
        down_index = search_h_upper(x, m - 1)
        return (right_index - left_index + 1) * (down_index - up_index + 1)



data = Solution()
image = [["0", "0", "1", "0"], ["0", "1", "1", "0"], ["1", "1", "0", "0"]]
x = 1
y = 1
print(data.minArea(image, x, y))